package com.bida.controller.admin;

import com.bida.domain.vo.OrderReportVO;
import com.bida.domain.vo.SalesTop10ReportVO;
import com.bida.domain.vo.TurnoverReportVO;
import com.bida.domain.vo.UserReportVO;
import com.bida.result.Result;
import com.bida.service.ReportService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

/**
 * @author 23087
 */
@RestController
@RequestMapping("/admin/report")
public class ReportController {

    @Resource
    private ReportService reportService;


    /**
     * 营业额统计接口
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> getTurnoverStatisticsInfo(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        TurnoverReportVO turnoverStatisticsInfo = reportService.getTurnoverStatisticsInfo(begin, end);
        return Result.success(turnoverStatisticsInfo);
    }

    /**
     * 用户统计接口
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/userStatistics")
    public Result<UserReportVO> getUserStatisticsInfo(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        UserReportVO userStatisticsInfo = reportService.getUserStatisticsInfo(begin, end);
        return Result.success(userStatisticsInfo);
    }

    /**
     * 订单统计接口
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ordersStatistics")
    public Result<OrderReportVO> getOrdersStatisticsInfo(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) throws Exception {
        OrderReportVO orderReportVO = reportService.getOrdersStatisticsInfo(begin, end);
        return Result.success(orderReportVO);
    }

    /**
     * 查询销量排名top10接口
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> getTop10Infos(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        SalesTop10ReportVO salesTop10ReportVO = reportService.getTop10Infos(begin, end);
        return Result.success(salesTop10ReportVO);
    }

    /**
     * 导出Excel报表接口( 30天数据 )
     * @return
     */
    @GetMapping("/export")
    public void exportReportExcelDate(HttpServletResponse response) {
        reportService.exportReportExcelDate(response);
    }


}
